package com.lovo.ssc.config;

import com.lovo.util.MQUtil;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: lf
 * @Date: 2022/7/8 10:59
 */
@Configuration
public class SellKillMqConfig {
    @Autowired
    CachingConnectionFactory connectionFactory;

    //rabbitmq模板
    @Bean(value = "rabbitTemplate")
    public RabbitTemplate rabbitTemplate() {
        return new RabbitTemplate(connectionFactory);
    }

    @Bean
    public Queue sellKillCheackQueue(){
        return new Queue(MQUtil.sellKillCheackQueue);
    }
    @Bean
    public Queue cancelCheackQueue(){
        return new Queue(MQUtil.cancelCheackQueue);
    }

    //默认交换机：DirectExchange
    @Bean
    public DirectExchange directExchangeSellKill(){
        return new DirectExchange(MQUtil.directExchangeSellKill);
    }
    @Bean
    //选择审核
    public Binding directExchangeSellKillToSellKillCheackQueuee(Queue sellKillCheackQueue,DirectExchange directExchangeSellKill) {
        return BindingBuilder.bind(sellKillCheackQueue).to(directExchangeSellKill).with(MQUtil.sellKillKeyOne);
    }
    @Bean
    //取消审核
    public Binding directExchangeSellKillToCancelCheackQueue(Queue cancelCheackQueue, DirectExchange directExchangeSellKill) {
        return BindingBuilder.bind(cancelCheackQueue).to(directExchangeSellKill).with(MQUtil.sellKillKeyThree);
    }

    //冻结队列
    @Bean
    public Queue frozenQueue(){
        return new Queue(MQUtil.frozenQueue);
    }

    //冻结交换机
    @Bean
    public DirectExchange directExchangeFrozen(){
        return new DirectExchange(MQUtil.frozenExchange);
    }

    //冻结绑定交换机和队列
    @Bean
    public Binding directExchangeFrozenToFrozenQueue(Queue frozenQueue,DirectExchange directExchangeFrozen){
        return BindingBuilder.bind(frozenQueue).to(directExchangeFrozen).with(MQUtil.frozenKey);
    }
}
